package org.mybatis.logic.mybatis;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;

@MappedJdbcTypes(JdbcType.NUMERIC)
public class CustomDateType extends BaseTypeHandler<Date> {

	@Override
	public Date getNullableResult(ResultSet arg0, String arg1) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Date getNullableResult(ResultSet rs, int columnIndex) throws SQLException {		
		Long date = rs.getLong( columnIndex );
		return new Date( date );		
	}

	@Override
	public Date getNullableResult(CallableStatement cs, int columnIndex)	throws SQLException {
		Long date = cs.getLong( columnIndex );
		return new Date( date );
	}

	@Override
	public void setNonNullParameter(PreparedStatement ps, int i, Date parameter, JdbcType jdbcType) throws SQLException {		
		ps.setLong(i, parameter.getTime());
	}


}
